<?



class People
{

    private $member_id;
    private $name;
    private $profileUrl;
    private $thumbnailUrl;
    private $access_token;
    private $refresh_token;

    function __construct($member_id = '@me')
    {
        $this->set_member_id($member_id);
    }
    
    private function set_member_id($member_id = '@me')
    {
        $this->member_id = $member_id;
    }
    
    public function set_access_token($access_token)
    {
        $this->access_token = $access_token;
    }

    public function set_refresh_token($refresh_token)
    {
        $this->refresh_token = $refresh_token;
    }

    public function get_member_id()
    {
        return $this->member_id;
    }

    public function get_name()
    {
        return $this->name;
    }

    public function get_profileUrl()
    {
        return $this->profileUrl;
    }

    public function get_thumbnailUrl()
    {
        return $this->thumbnailUrl;
    }

    public function get_profile($member_id = '@me')
    {

        $url = 'http://api.mixi-platform.com/2/people/'.$this->member_id.'/@self';
        
        $data = array(
            'oauth_token' => $this->access_token,
        );

        $headers = array(
            'Authorization: OAuth '.$this->access_token, 
        );

        $options = array('http' => array(
            'method' => 'GET',
            'content' => http_build_query($data),
            'header' => implode("\r\n", $headers),
        ));

        $contents = file_get_contents($url, false, stream_context_create($options));
        
        if($http_response_header[0] == 'HTTP/1.1 200 OK')
        {
            $data = json_decode($contents);
            $this->member_id = $data->entry->id;
            $this->name = $data->entry->displayName;
            $this->profileUrl = $data->entry->profileUrl;
            
            //preDump($data);
            
            return true;
            //echo "OK";
        }
        else
        {
            return false;
            //echo "NG";
        }
    }


}


/*
$url = 'http://api.mixi-platform.com/2/people/@me/@friends';
$data = array(
    'oauth_token' => 'b5e505666cddae4a5fd61e594aca75e50b05eaff',
);

$headers = array(
    'Authorization: OAuth b5e505666cddae4a5fd61e594aca75e50b05eaff', 
);

$options = array('http' => array(
    'method' => 'GET',
    'content' => http_build_query($data),
    'header' => implode("\r\n", $headers),
));
$contents = file_get_contents($url, false, stream_context_create($options));


preDump(json_decode($contents));


function preDump($data){

    echo '<pre>';
    var_dump($data);
    echo '</pre>';
}
*/

?>